package com.ssm;

import java.net.URL;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

import android.net.Uri;
import android.util.Log;

public class NaverAPI {

	
	static public ArrayList<String> Quary(String keyword)
	{
		ArrayList<String> result = new ArrayList<String>();
		
		
		try {

			String key = "150085be46b5f03ab21a97e5eb1731ea";
			String quary = Uri.encode(keyword);
			URL text = new URL("http://openapi.naver.com/search?key=" + key + 
					"&query=" + quary + 
					"&target=recmd");
			

			XmlPullParserFactory parserCreator = XmlPullParserFactory
					.newInstance();
			XmlPullParser parser = parserCreator.newPullParser();

			parser.setInput(text.openStream(), null);

			Log.i("NET", "Parsing...");

			// status.setText("Parsing....");

			int parseEvent = parser.getEventType();
			while (parseEvent != XmlPullParser.END_DOCUMENT) {

				switch (parseEvent) {
				case XmlPullParser.START_TAG:
					String tag = parser.getName();				

					if(tag.compareTo("item") == 0) {
						String item = parser.nextText();
						//Log.i("item", titleSrc);
						result.add(item);
					}
								
					break;
				}
				parseEvent = parser.next();

				// xmlData = null;
				// While next ´ÙÀ½À¸·Î ³Ñ±ä´Ù.
			}
			Log.i("NET", "End...");

		} catch (Exception e) {
			// TODO: handle exception
			Log.i("NET", "Parsing Failed!");
		}
		
		
		return result;
	}
}
